package timex

import "time"

const (
	day = 24 * time.Hour
)

func TimeDuration(count int, unit string) time.Duration {
	switch unit {
	case "ss":
		return time.Second * time.Duration(count)
	case "mm":
		return time.Minute * time.Duration(count)
	case "hh":
		return time.Hour * time.Duration(count)
	case "DD":
		return day * time.Duration(count)
	case "MM":
		return time.Since(time.Now().AddDate(0, count, 0))
	case "YY":
		return time.Since(time.Now().AddDate(count, 0, 0))
	default:
		return time.Minute * time.Duration(count)
	}
}
func TimeNowDuration(count int, unit string) time.Time {
	now := time.Now()
	switch unit {
	case "ss":
		return now.Add(time.Second * time.Duration(count))
	case "mm":
		return now.Add(time.Minute * time.Duration(count))
	case "hh":
		return now.Add(time.Hour * time.Duration(count))
	case "DD":
		return now.Add(day * time.Duration(count))
	case "MM":
		return now.AddDate(0, count, 0)
	case "YY":
		return now.AddDate(count, 0, 0)
	default:
		return now.Add(day * time.Duration(count))
	}
}
